import java.util.Arrays;

public class Test {
    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int i = m - 1;
        int j = n - 1;
        int k = m + n - 1;
        while (i >= 0 && j >= 0) {
            if (nums1[i] > nums2[j]) {
                nums1[k--] = nums1[i--];
            } else {
                nums1[k--] = nums2[j--];
            }
        }
        System.out.println(i + " " + j + " " + k);
        while (i >= 0) {
            nums1[k--] = nums1[i--];
        }
        while (j >= 0) {
            nums1[k--] = nums2[j--];
        }
    }

    public static void main1(String[] args) {
        int[] nums1 = {4, 5, 6, 0, 0, 0};
        int[] nums2 = {1, 2, 3};
        merge(nums1, 3, nums2, 3);
        System.out.println(Arrays.toString(nums1));
    }

    public ListNode middleNode() {
        if (head == null) {
            return null;
        }
        ListNode fast = head;
        ListNode slow = head;
        while(fast!=null&&fast.next!=null) {
            fast = fast.next.next;
            slow = slow.next;
        }
        return slow;
    }

    public ListNode findKthToTail(int k) {
        if(k <= 0 || k > size()) {
            return null;
        }
        ListNode fast = head;
        ListNode slow = head;

        int cnt = 0;
        while(cnt<k) {
            fast = fast.next;
            cnt++;
        }
        while(fast.next!=null) {
            fast = fast.next;
            slow = slow.next;
        }
        return slow;
    }
}





   /* public void clear() {
        ListNode cur = he 6rfgt5ad;
        while(cur!=null) {
            ListNode next = cur.next;
            cur.val = null;
            cur.next = null;
            cur = next;
        }
        head = null;
    }

    public ListNode reverseList() {
        if (head == null) {
            return null;
        }
        //只有一个节点
        if (head.next == null) {
            return head;
        }

        ListNode cur = head.next;
        while (cur != null) {
            ListNode curNext = cur.next;
            if (cur == head) {
                cur.next = null;
            } else {
                cur.next = head;
                head = cur;
                cur = curNext;
            }
        }
        return head;
    }
*/















